import 'package:get/get.dart';

import '../../../models/category_model.dart';
import '../../../serives/httpsClient.dart';

class CagegoryController extends GetxController {
  RxList<CategoryItem> leftCategoryList = <CategoryItem>[].obs;
  RxList<CategoryItem> rightCategoryList = <CategoryItem>[].obs;
  HttpsClient httpsClient = HttpsClient();

  RxInt selectIndex = 0.obs;
  @override
  void onInit() {
    super.onInit();
    getLeftCategoryData();
  }

  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onClose() {
    super.onClose();
  }

  void changeselectIndex(index, id) {
    selectIndex.value = index;
    getRightCategoryData(id);
    update();
  }

  getLeftCategoryData() async {
    var response = await httpsClient.get("api/pcate");
    var category = CategoryModel.fromJson(response.data);
    leftCategoryList.value = category.result!;
    getRightCategoryData(leftCategoryList[0].sId!);
    update();
  }

  getRightCategoryData(String pid) async {
    var response = await httpsClient.get("api/pcate?pid=$pid");
    var category = CategoryModel.fromJson(response.data);
    rightCategoryList.value = category.result!;
    update();
  }
}
